<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/";%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <base href="<%=basePath %>">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数据源执行日志记录</title>
    <link href="static/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="static/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="static/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="static/css/animate.css" rel="stylesheet">
    <link href="static/css/style.css?v=4.1.0" rel="stylesheet">
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>数据源执行日志记录</h5>
            <div class="ibox-tools">
                <a class="collapse-link">
                    <i class="fa fa-chevron-up"></i>
                </a>
                <a class="close-link">
                    <i class="fa fa-times"></i>
                </a>
            </div>
        </div>
        <div class="ibox-content">
            <div class="row">
                <div class="col-sm-5">
                    <a href="view/database/monitor/listUI.shtml" class="btn btn-w-m btn-info" type="button">
                        <i class="fa fa-reply" aria-hidden="true"></i>&nbsp;返回
                    </a>
                </div>
                <div class="col-sm-7">
                    <div class="form-inline text-right">
                        <div class="form-group">
                            <label class="control-label m-b-xs" for="startTime">起始时间：</label>
                            <input type="text" id="startTime" name="startTime" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',maxDate:'#F{$dp.$D(\'finishTime\')||\'2050-10-01\'}'})" class="form-control m-b-xs" />
                        </div>
                        <div class="form-group">
                            <label class="control-label m-b-xs" for="finishTime">结束时间：</label>
                            <input type="text" name="finishTime" id="finishTime" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'#F{$dp.$D(\'startTime\')}',maxDate:'2050-10-01'})" class="form-control m-b-xs"/>
                        </div>
                        <div class="form-group">
                            <button onclick="search()" class="right btn btn-w-m btn-info" type="button">
                                <i class="fa fa-search" aria-hidden="true"></i>&nbsp;搜索
                            </button>
                        </div>
                    </div>
                </div>
            </div>
            <input type="hidden" id="databaseId" name="databaseId" value="${databaseId }">
            <table id="databaseRecordList" data-toggle="table"
                   data-url="database/record/getList.shtml"
                   data-query-params=queryParams data-query-params-type="limit"
                   data-pagination="true"
                   data-side-pagination="server" data-pagination-loop="false" data-cache="false">
                <thead>
                <tr>
                    <th data-field="databaseName">数据源名称</th>
                    <th data-field="databaseType" data-formatter="databaseTypeFormatter">数据源类型</th>
                    <th data-field="databaseStatus" data-formatter="recordStatusFormatter">数据源执行状态</th>
                    <th data-field="jobortransId" data-formatter="sourceNameFormatter">资源名称</th>
                    <th data-field="sourceType" data-formatter="sourceTypeFormatter">资源类型</th>
                    <th data-field="executeTime">数据源执行时间</th>
                </tr>
                </thead>
            </table>
        </div>
    </div>
</div>
<!-- 全局js -->
<script src="static/js/jquery.min.js?v=2.1.4"></script>
<script src="static/js/bootstrap.min.js?v=3.3.6"></script>
<script src="static/js/My97DatePicker/WdatePicker.js"></script>
<!-- layer javascript -->
<script src="static/js/plugins/layer/layer.min.js"></script>
<!-- 自定义js -->
<script src="static/js/content.js?v=1.0.0"></script>
<!-- Bootstrap table -->
<script src="static/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
<script src="static/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
<script src="static/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<script>
    $(document).ready(function () {
        var $databaseId = $("#databaseId").val();
        // $("#jobId").find("option[value=" + $databaseId + "]").prop("selected", true);
        // search();
    });

    function databaseTypeFormatter(value, row, index){
        if (value == 1){
          return "输入源"
        }else if(value == 2){
          return "输出源"
        }else{
          return "未定义"
        }
    }

    function sourceTypeFormatter(value, row, index) {
        if (value == 1){
          return "作业"
        }else if (value == 2){
          return "转换"
        }else{
          return "未定义"
        }
    };

    function sourceNameFormatter(value, row, index) {
        var recordJob = "";
      var base = $("base")[0].href;
        $.ajax({
          type: 'POST',
          async: false,
          url: base+'job/getJob.shtml',
          data: {
            "jobId": value
          },
          success: function (data) {
            var Job = data.data;
            recordJob = Job.jobName;
          },
          error: function () {
            alert("系统出现问题，请联系管理员");
          },
          dataType: 'json'
        });
        return recordJob;
    };

    function recordStatusFormatter(value, row, index){
        if (row.successCount==1){
          return "成功"
        }else if (row.failCount==1){
          return  "失败"
        }else{
          return  "未定义"
        }
    }

    function queryParams(params) {
        var $databaseId = $("#databaseId").val();
        var $startTime = $("#startTime").val();
        var $finishTime = $("#finishTime").val();
        var temp = {limit: 10, offset: params.offset, databaseId: $databaseId, startTime: $startTime,finishTime:$finishTime };
        return temp;
    };

    function search() {
      var base = $("base")[0].href;
        $('#databaseRecordList').bootstrapTable('refresh', base+"database/record/getList.shtml");
    };

</script>
</body>
</html>